﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DAL;
using Models;
using Common;

namespace 包覆门
{
    public partial class loginForm : Form
    {
        public loginForm()
        {
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            string username =tbLoginName.Text.Trim();
            string password =tbPassword.Text.Trim();
            if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password))
            {
                MessageBox.Show("用户名或密码不能为空");
                return;
            }
            Operator or = new OperatorDAL().GetBuUsername(username);
            if (or == null)
            {
                MessageBox.Show("用户名或密码错误");
                return;
            }
            else {
                if (or.Password.Equals(password))
                {

                    MessageBox.Show("登录成功");
                    RemeberName.Username = username;
                    RemeberName.IsAdmin = or.IsAdmin;
                    RemeberName.Realname = or.realname;
                    this.DialogResult = DialogResult.OK;
                }
                else {
                    MessageBox.Show("用户名或密码错误");
                    return;
                }
            }

            
            //this.Close();
        }

        private void tbnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void btnLogin_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter) {
                this.btnLogin_Click(sender,e);
            }
        }
    }
}
